/**
 * @param {number[]} nums
 * @return {number}
 */
var minimumSum = function(nums) {
    const len = nums.length
    const left = new Array(len).fill(undefined)
    const right = new Array(len).fill(undefined)
    let min = undefined
    for ( let i = 0;i < len;i++) {
        left[i] = (left[i- 1] && (left[i - 1] < nums[i])) ? left[i - 1] : nums[i] 
    }
    for ( let i = len - 1;i >= 0;i--) {
        right[i] = (right[i + 1] && (right[i + 1] < nums[i])) ? right[i + 1] : nums[i] 
    }
    console.log(left,right)
    for ( let i = 0;i < len;i++) {
        if (nums[i] > left[i-1] && nums[i] > right[i+1] ) min =  min && min < nums[i] +left[i-1] + right[i+1] ? min : nums[i] +left[i-1] + right[i+1]
    }
    console.log(min)
    return min || -1
};
const nums = [6,5,4,3,4,5]
console.log(minimumSum(nums))